local pianyi = fk.CreateSkill({
  name = "jy__pianyi",
})

pianyi.jy__zhongliu_type = Player.HistoryPhase

pianyi:addEffect("active", {
  anim_type = "offensive",
  target_num = 1,
  can_use = function(self, player)
    return player:usedSkillTimes(pianyi.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return  to_select:getMark("@@jy__pianyi-turn")==0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    if player == target then
      player:broadcastSkillInvoke(pianyi.name, 3)
    end
    room:addPlayerMark(target, "@@jy__pianyi-turn")
    local cards = target:getCardIds("h")
    room:useVirtualCard("analeptic", cards, target, target, pianyi.name)
    local choice = room:askToChoice(target, {
        choices = {"摸其中非黑桃牌数量张牌" , "依次使用其中的黑桃牌"},
        prompt = "貂蝉 将执行另一项",
        skill_name = pianyi.name
    })
    local num = #table.filter(cards, function(id)
        return Fk:getCardById(id).suit ~= Card.Spade
    end)
    if choice == "摸其中非黑桃牌数量张牌" then

      target:drawCards(num,pianyi.name)

      if not player.dead and cards  then
          for _, id in ipairs(cards) do
              if player.dead  then break end
              if (Fk:getCardById(id).suit == Card.Spade)then
                  room:askToUseRealCard(player, {
                      pattern = { id },
                      skill_name = pianyi.name,
                      extra_data = {
                      bypass_times = true,
                      expand_pile = { id },
                      extraUse = true,
                      },
                   })
              end
          end
      end

    else

      if not target.dead and cards  then
          for _, id in ipairs(cards) do
              if target.dead  then break end
              if (Fk:getCardById(id).suit == Card.Spade)then
                  room:askToUseRealCard(target, {
                      pattern = { id },
                      skill_name = pianyi.name,
                      extra_data = {
                      bypass_times = true,
                      expand_pile = { id },
                      extraUse = true,
                      },
                   })
              end
          end
      end

      player:drawCards(num,pianyi.name)

    end
  end,
})

Fk:loadTranslationTable{
  ["jy__pianyi"] = "翩仪",
  [":jy__pianyi"] = "出牌阶段限一次，你可以令一名本回合未成为过此技能目标的角色将所有手牌当【酒】使用，然后其抉择：1.摸其中非黑桃牌数量张牌；2.依次使用其中的黑桃牌。然后你执行另一项。",
  ["$jy__pianyi1"] = "将军盖世英雄，只恨小女身许太师，却难共饮。",
  ["$jy__pianyi2"] = "太师且饮此杯，吕布公之义子，不宜生隙。",
  ["$jy__pianyi3"] = "杯酒相庆，今日董贼当伏诛",
  ["@@jy__pianyi-turn"] = "翩仪：选择过"
}

return pianyi

